package MyCode.Swing.JFrameDemo;

import javax.swing.*;
import java.awt.*;

public class Gui4 extends JFrame {

    public static final int size = 9;
    //定义组件
    JButton[] btns = new JButton[9];

    public Gui4() {
        //创建组件
        for (int i = 0; i < size; i++) {
            btns[i] = new JButton("" + i);
        }

        //设置网格布局
        setLayout(new GridLayout(3, 3, 5, 5));

        //添加组件
        for (int i = 0; i < size; i++) {
            add(btns[i]);
        }

        //设置窗体属性
        setTitle("网格布局");
        setSize(300,300);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);

    }

    public static void main(String[] args) {
        new Gui4();
    }

}
